#!/bin/bash

function check_pvestatd () {

    check_status=`systemctl --no-pager status pvestatd|grep 'Active:'|grep 'active'|grep 'running'|wc -l`;

    if [ "${check_status}" != "0" ];then
      echo "`date` [CHECK_INFO]`systemctl status pvestatd|grep 'Active:'|grep 'active'`";
      echo "`date` [CHECK_INFO]     Check pvestatd status pass......"
    fi


}



function restart_pvestatd () {
    echo "`date` check pvestatd......"
    systemctl --no-pager status  pvestatd
    echo "`date` restart pvestatd......"
    systemctl restart  pvestatd;
    echo "`date` check pvestatd......"
    systemctl --no-pager status pvestatd ;
    echo '----------------------------------------';



}



######
logs_path=/var/log/repvestatd.log

###auto create logs_path

check_pvestatd
if [ "${check_status}" == "0" ];then

    restart_pvestatd 2>&1|tee -a ${logs_path};
else
    sed -i '/CHECK_INFO/d'  ${logs_path};
    check_pvestatd 2>&1|tee -a ${logs_path}
fi
